<template>
  <!-- 编辑汇率 -->
  <a-modal :width="400" v-model:visible="showEditRateDialog" title="修改汇率" title-align="start" :mask-closable="false" @cancel="closedDialog" :ok-loading="submitLoading" :on-before-ok="saveData">
    <div class="item">币种：{{ currentItem.currencyChName }}</div>
    <div class="item">货币代码：{{ currentItem.currency }}</div>
    <div class="item">月份：{{ currentItem.gmtRate }}</div>
    <div class="item">官方汇率：{{ currentItem.officialRate }}</div>
    <div class="flex-c item">
      <p>本地汇率：</p>
      <a-input-number v-model="rate" style="width: 200px" placeholder="" :precision="4" />
    </div>
  </a-modal>
</template>
<script lang="ts" setup>
  import { ref } from 'vue'
  import { Message } from '@arco-design/web-vue'
  import { updateExchangeRate } from '@/api/system'
  const emit = defineEmits(['closed', 'success'])
  const props = defineProps({
    isShow: {
      type: Boolean,
      default: false,
    },
    currentItem: {
      type: Object,
      default: () => {},
    },
  })

  const showEditRateDialog = ref(props.isShow)
  const submitLoading = ref(false)
  const rate = ref(props.currentItem.localRate)

  // 同步
  async function saveData() {
    if (!rate.value) {
      Message.error('请输入本地汇率')
      return false
    }
    const res: any = await updateExchangeRate({
      localRate: rate.value,
      id: props.currentItem.id,
    })
    if (!res) return false
    Message.success('更新成功')
    emit('success')
    emit('closed')
  }
  // 关闭
  function closedDialog() {
    showEditRateDialog.value = false
    emit('closed')
  }
</script>
<style lang="less" scoped>
  .item {
    margin-bottom: 15px;
  }
</style>
